package com.ityshow.uaa.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * A OauthAccessToken.
 */
@Entity
@Table(name = "oauth_access_token")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "oauthaccesstoken")
public class OauthAccessToken implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    @Column(name = "token_id", nullable = false)
    private String tokenId;

    @Column(name = "token")
    private String token;

    @NotNull
    @Column(name = "authentication_id", nullable = false)
    private String authenticationId;

    @Column(name = "user_name")
    private String userName;

    @Column(name = "client_id")
    private String clientId;

    @Column(name = "authentication")
    private String authentication;

    @Column(name = "refresh_token")
    private String refreshToken;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTokenId() {
        return tokenId;
    }

    public OauthAccessToken tokenId(String tokenId) {
        this.tokenId = tokenId;
        return this;
    }

    public void setTokenId(String tokenId) {
        this.tokenId = tokenId;
    }

    public String getToken() {
        return token;
    }

    public OauthAccessToken token(String token) {
        this.token = token;
        return this;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getAuthenticationId() {
        return authenticationId;
    }

    public OauthAccessToken authenticationId(String authenticationId) {
        this.authenticationId = authenticationId;
        return this;
    }

    public void setAuthenticationId(String authenticationId) {
        this.authenticationId = authenticationId;
    }

    public String getUserName() {
        return userName;
    }

    public OauthAccessToken userName(String userName) {
        this.userName = userName;
        return this;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getClientId() {
        return clientId;
    }

    public OauthAccessToken clientId(String clientId) {
        this.clientId = clientId;
        return this;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getAuthentication() {
        return authentication;
    }

    public OauthAccessToken authentication(String authentication) {
        this.authentication = authentication;
        return this;
    }

    public void setAuthentication(String authentication) {
        this.authentication = authentication;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public OauthAccessToken refreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
        return this;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        OauthAccessToken oauthAccessToken = (OauthAccessToken) o;
        if (oauthAccessToken.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, oauthAccessToken.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "OauthAccessToken{" +
            "id=" + id +
            ", tokenId='" + tokenId + "'" +
            ", token='" + token + "'" +
            ", authenticationId='" + authenticationId + "'" +
            ", userName='" + userName + "'" +
            ", clientId='" + clientId + "'" +
            ", authentication='" + authentication + "'" +
            ", refreshToken='" + refreshToken + "'" +
            '}';
    }
}
